package www.nupter.org.njuptask.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.http.HttpMethod;
import org.xutils.http.RequestParams;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import me.nereo.multi_image_selector.MultiImageSelectorActivity;
import www.nupter.org.njuptask.R;
import www.nupter.org.njuptask.http.HttpCallBack;
import www.nupter.org.njuptask.http.HttpRequestUtil;
import www.nupter.org.njuptask.http.RequestUrl;
import www.nupter.org.njuptask.model.BaseInfo;
import www.nupter.org.njuptask.utils.DataUtils;


/**
 * A login screen that offers login via email/password.
 */
public class PublishQuestionReplyActivity extends BaseActivity {

    private EditText contentEdit;

    private int questionId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publish_reply_question);
        setTitle("回复问题");
        setRightText("提交");
        contentEdit = (EditText) findViewById(R.id.des);
        Intent intent = getIntent();
        questionId = Integer.valueOf(intent.getStringExtra("questionId"));
    }

    @Override
    protected void HandleTitleBarEvent(TitleBar component, View v) {
        if (component == TitleBar.LEFT) {
            finish();
        }else if (component==TitleBar.RightText){
            saveQuestion();
        }
    }

    public void saveQuestion(){
        RequestParams requestParams=new RequestParams(RequestUrl.add_reply);
        requestParams.addBodyParameter("content",contentEdit.getText().toString());
        requestParams.addBodyParameter("userId", DataUtils.getPreferences("userId","1"));
        requestParams.addBodyParameter("questionId",String.valueOf(questionId));
        HttpRequestUtil.postMethod(requestParams, BaseInfo.class, new HttpCallBack<BaseInfo>() {
            @Override
            public void success(BaseInfo data) {
                finish();
            }
            @Override
            public void erro(String res) {
               BaseToast(res);
            }
        });
    }

}

